﻿@using WebApp.Models

@model  IEnumerable<MenuItem>
<!-- Left panel : Navigation area -->
<!-- Note: This width of the aside area can be adjusted through LESS variables -->
<aside id="left-panel">
    <!-- User info -->
    @{ Html.RenderPartial("_CurrentUser"); }
    <!-- end user info -->
    <!-- NAVIGATION : This navigation is also responsive

    To make this navigation dynamic please make sure to link the node
    (the reference to the nav > ul) after page load. Or the navigation
    will not initialize.
    -->
    <nav >
        <!-- NOTE: Notice the gaps after each icon usage <i></i>..
        Please note that these links work a bit different than
        traditional href="" links. See documentation for details.
        -->

        <ul>
           
            @{
                var nodes = Model;
                if (nodes.Any())
                {
                    foreach (var node in nodes.Where(x => x.ParentId == null))
                    {
                        @RenderSubMenuRecursive(node)
                    }
                }
            }

            @helper RenderSubMenuRecursive(WebApp.Models.MenuItem node)
            {

var childNodes = Model.Where(x => x.ParentId == node.Id);
if (childNodes.Any())
{
    var childcontrollers = String.Join("", childNodes.Select(x => String.Format(",{0}", x.Controller)).Distinct()).Substring(1);
    var icon = String.IsNullOrEmpty(node.IconCls) ? "fa fa-lg fa-fw fa-folder-o" : node.IconCls;
        <li class="@Html.IsSelected(controller: childcontrollers)">
            <a href="#" title="@node.Description"><i class="@icon"></i> <span class="menu-item-parent">@node.Title</span> </a>
            <ul>
                @foreach (var childNode in childNodes)
                {
                    @RenderSubMenuRecursive(childNode)
                }
            </ul>
        </li>
}
else
{

        <li class="@Html.IsSelected(action:node.Action, controller: node.Controller)">
            <a href="@node.Url" title="@node.Description">
            <span class="menu-item-parent">@node.Title</span>
            </a>
        </li>

}





}
        </ul>
    </nav>
    <span class="minifyme" data-action="minifyMenu">
        <i class="fa fa-arrow-circle-left hit"></i>
    </span>

</aside>
